<div ng-controller="orderAddC">
    <div class="modal fade" id="dlg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">客户选择</h4>
                </div>
                <div class="modal-body">
                    <div class="input-group ">
                        <input class="selectFind form-control" type="text" ng-model="searchTxt" placeholder="查找" ng-change="FindAllBy()">
                        <span class="glyphicon glyphicon-remove input-group-addon" ng-click="empty()"></span>
                    </div>
                    <div class="selectShow" style=" width: 100%; height: 200px;border:1px solid #CCCCCC;overflow:scroll;">
                        <!--<div style="cursor:pointer;" class="form-control" ng-click="selectEmp(x)" ng-repeat="x in client | filter:{ShortName : searchTxt} | filter:{Name : searchTxt}">{{x.ShortName}}</div>-->
                        <div style="cursor:pointer;" class="form-control" ng-click="selectEmp(x)" ng-repeat="x in client | filter:{ShortName : searchTxt}">{{x.ShortName}}</div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">创建计划单--{{typeName}}</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive" ng-show="isshow">
                <form name="form" class="bs-example form-horizontal">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">客户(必填)</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input required="required" ng-model="client1.ShortName" class="form-control text-left kehu" type="text" data-toggle="modal" data-target="#dlg">
                                    </input>
                                    <!--<span class="help-block m-b-none">Example block-level help text here.</span>-->
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">公司户头</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <select required="required" ng-change="sum()" ng-click="none()" class="form-control" ng-model="data1.Account" ng-options="value.Name for value in client1.Accounts"></select>
                                    <!--<span class="help-block m-b-none">Example block-level help text here.</span>-->
                                </div>
                                <!--<label>公司户头（必填）</label>-->
                                <!--<select required="required" ng-change="sum()" class="form-control" ng-model="data1.Account" ng-options="value.Name for value in client1.Accounts"></select>-->
                            </div>
                           <!--  <div class="form-group" ng-if="!orderdata.IsDelivery">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-12  control-label" style="padding-right: 0px;">目的地(必填)</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-12">
                                    <div class="input-group ">
                                        <span class="input-group-addon">省</span>
                                        <select required="required" class="form-control" ng-options="x.FillName for x in items" ng-model="selectedDistrict1"></select>
                                        <span class="input-group-addon">市</span>
                                        <select required="required" class="form-control" ng-model="orderdata.DistrictId" name="District">
                                            <option ng-repeat="y in selectedDistrict1.Children" value="{{y.Id}}">{{y.Name}}</option>
                                        </select>
                                    </div>
                                </div>
                            </div> -->
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-12  control-label" style="padding-right: 0px;">目的地(必填)</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-12">
                                    <div class="input-group ">
                                        <span class="input-group-addon">省</span>
                                        <select class="form-control" ng-options="x.FillName for x in items" ng-model="selectedDistrict1"></select>
                                        <span class="input-group-addon">市</span>
                                        <select class="form-control" ng-model="orderdata.DistrictId" name="District" required>
                                            <option ng-repeat="y in selectedDistrict1.Children" value="{{y.Id}}">{{y.Name}}</option>
                                        </select>
                                    </div>
                                    <!--<span class="help-block m-b-none">Example block-level help text here.</span>-->
                                </div>
                                <!--<label>目的地</label>-->
                                <!--<div class="input-group ">-->
                                    <!--<span class="input-group-addon">省</span>-->
                                    <!--<select class="form-control" ng-options="x.FillName for x in items" ng-model="selectedDistrict1"></select>-->
                                    <!--<span class="input-group-addon">市</span>-->
                                    <!--<select class="form-control" ng-model="orderdata.DistrictId" name="District">-->
                                        <!--<option ng-repeat="y in selectedDistrict1.Children" value="{{y.Id}}">{{y.Name}}</option>-->
                                    <!--</select>-->
                                <!--</div>-->
                            </div>
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">具体地址</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input ng-model="orderdata.Address" type="text" class="form-control">
                                    <!--<span class="help-block m-b-none">Example block-level help text here.</span>-->
                                </div>
                                <!--<label>具体地址</label>-->
                                <!--<input ng-model="orderdata.Address" type="text" class="form-control">-->
                            </div>
                            <div class="form-group">
                                <!--<div class="col-lg-offset-1 col-md-offset-2 col-sm-offset-2 col-xs-offset-3 col-lg-11 col-md-10 col-sm-10 col-xs-9">-->
                                    <div class="checkbox" style="padding-left: 15px" >
                                        <label for="xiankuan" style="margin-right: 10px;padding: 0px">是否先款</label>
                                        <label class="i-checks">
                                            <input type="checkbox" id="xiankuan" ng-click="backf()" ng-change="sum()" ng-model="orderdata.IsFullPayment">
                                            <i></i>
                                        </label>
                                        <label for="suojia" style="margin-right: 10px;">是否锁价</label>
                                        <label class="i-checks">
                                            <input type="checkbox" id="suojia" ng-model="orderdata.IsLockPrice">
                                            <i></i>
                                        </label>
                                        <label for="zipai" style="margin-right: 10px;" ng-click="zipai()">是否自派</label>
                                        <label class="i-checks" ng-click="zipai()">
                                            <input type="checkbox" id="zipai" ng-model="orderdata.IsDelivery">
                                            <i></i>
                                        </label>
                                    <!--</div>-->
                                </div>
                            </div>
                            <div class="form-group" ng-if="!(orderdata.IsDelivery || data1.Account.IsCash)">
                                <div class="checkbox" style="padding-left: 15px">
                                <label for="gonghu" style="margin-right: 10px;padding: 0px">运费是否公户</label>
                                <label class="i-checks">
                                    <input type="checkbox" id="gonghu" ng-model="orderdata.IsPublicDelivery">
                                    <i></i>
                                </label>
                                </div>
                            </div>
                            <div class="form-group" ng-if="!orderdata.IsDelivery">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">每吨运费</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input ng-change="sum()" ng-model="orderdata.DeliveryPrice" type="number" min="0" placeholder="请输入每吨运费" class="form-control">
                                </div>

                                <!--<label>每吨运费</label>-->
                                <!--<input ng-change="sum()" ng-model="orderdata.DeliveryPrice" type="number" min="0" class="form-control">-->
                            </div>
                            <div class="form-group" ng-if="orderdata.IsDelivery">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">车辆信息</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" ng-model="orderdata.VehicleInfos" class="form-control" placeholder="请输入车辆信息(每条信息以英文逗号分隔)" maxlength="100">
                                </div>
                                <!--<label>车辆信息(每条信息以英文逗号分隔)</label>-->
                                <!--<input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" ng-model="orderdata.VehicleInfos" class="form-control" placeholder="请输入车辆信息（100字内）" maxlength="100">-->
                            </div>
                            <div class="form-group" ng-if="orderdata.IsDelivery">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">联系人</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" ng-model="orderdata.Contact" class="form-control" placeholder="请输入联系人信息(每条信息以英文逗号分隔)">
                                </div>
                                <!--<label>联系人(每条信息以英文逗号分隔)</label>-->
                                <!--<input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" ng-model="orderdata.Contact" class="form-control" placeholder="请输入联系人">-->
                            </div>
                            <div class="form-group" ng-if="orderdata.IsDelivery">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">联系方式</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input type="text" ng-model="orderdata.ContactPhone" class="form-control" ng-pattern="/^[0-9,]+$/" placeholder="请输入联系人手机号(每条信息以英文逗号分隔)">
                                </div>
                                <!--<label>联系人手机号(每条信息以英文逗号分隔)</label>-->
                                <!--<input type="text" ng-model="orderdata.ContactPhone" class="form-control" ng-pattern="/^[0-9,]+$/" placeholder="请输入联系人手机号">-->
                            </div>
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">备注信息</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input ng-model="orderdata.Remarks" type="text" class="form-control" placeholder="请输入备注信息（100字内）" maxlength="100">
                                </div>
                                <!--<label>备注</label>-->
                                <!--<input ng-model="orderdata.Remarks" type="text" class="form-control" placeholder="请输入备注信息（100字内）" maxlength="100">-->
                            </div>
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">单价优惠</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <input ng-change="sum()" ng-model="orderdata.ApplyDiscount" type="number" min="0" placeholder="申请单价优惠 元/吨  (默认为0)" class="form-control">
                                </div>
                                <!--<label>申请单价优惠 元/吨  (默认为0) </label>-->
                                <!--<input ng-change="sum()" ng-model="orderdata.ApplyDiscount" type="number" min="0" class="form-control">-->
                            </div>
                            <!--<div class="form-group">
                                <label>申请总价优惠</label>
                                <input ng-model="orderdata.BargainingAmount" type="number" class="form-control">
                            </div>-->
                            <div class="form-group">
                                <label class="col-lg-1 col-md-2 col-sm-2 col-xs-3  control-label" style="padding-right: 0px;">供应商</label>
                                <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9">
                                    <select ng-change="change1()" id="depot" class="form-control cangku" ng-options="x.Name for x in cangku" ng-model="Providerdata" name="cangku"></select>
                                </div>
                                <label ng-if="toggleText;"  style="padding-right: 0px;margin-left: 100px;color: #f00">当前供应商不允许使用现金户头！</label>
                                <!--<label>供应商&#45;&#45;{{typeName}}</label>-->
                                <!--<select ng-change="change1()" id="depot" class="form-control cangku" ng-options="x.Name for x in cangku" ng-model="Providerdata" name="cangku"></select>-->
                            </div>
                            <!--<div ng-if="orderdata.IsFullPayment" class="form-group">-->
                                <!--<lable>先款优惠：{{xiankuan}}/吨</lable>-->
                            <!--</div>-->
                            <div ng-if="orderdata.IsFullPayment"  class="row text-left container-fluid">
                                <span>先款优惠：{{ xiankuan | number:2}}/吨</span>
                                <!--<h4 style="display: inline-block">总价：{{orderdata.Total}}</h4>-->
                            </div>
                            <div ng-if="data1.Account.IsCash" class="row text-left container-fluid">
                                <span>非标优惠：{{feibiao | number:2}}/吨</span>
                                <!--<h4 style="display: inline-block">总价：{{orderdata.Total}}</h4>-->
                            </div>
                            <!--<div ng-if="data1.Account.IsCash" class="form-group">-->
                                <!--<lable>非标优惠：{{feibiao}}/吨</lable>-->
                            <!--</div>-->
                        </div>
                        <div class="container-fluid bg-light lter">
                            <div class="row" style="height: 40px;">
                                <div class="col-xs-6 col-md-6 text-left">
                                    <strong style="display: inline-block;line-height: 40px">购物车</strong>
                                </div>
                                <a>
                                <div ng-click="xxx()" class="col-xs-6 col-md-6 text-right" style="display: inline-block;line-height: 100%;height: 100%">
                                    <span style="display: inline-block;line-height: 40px">去选商品&nbsp;&nbsp;
                                        <i class="fa fa-chevron-right text"></i>
                                    </span>
                                </div>
                                </a>
                            </div>
                            <!--<div class="row text-right">-->
                                <!--<button type="button" class="btn btn-sm btn-success" ng-click="xxx()">去选商品</button>-->
                            <!--</div>-->
                        </div>
                        <div class="container-fluid" style="padding-top: 10px">
                                <div class="panel panel-default" ng-repeat="item in orderdata.CommodityInfos" style="margin-bottom: 10px">
                                    <div class="panel-heading">
                                        <div>钢厂：{{item.Commodity.Brand}}</div>
                                    </div>
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="col-xs-9 col-md-9">
                                                <!--<div>钢厂：{{item.Commodity.Brand}}</div>-->
                                                <div ng-if="ji">{{zuihou}}</div>
                                                <div>名称/材质/规格：{{item.Commodity.Name}}/{{item.Commodity.Standard}}/{{item.Commodity.Format}}</div>
                                                <div>售价：<input ng-blur="sum()" type="number" ng-blur="minpriceFn(item)" ng-model="item.Price"><i style="font-size: 0.8em; color: #999;">最小售价：{{item.minPrice}}（售价不能低于最低售价）</i></div>
                                                <div>最终售价：<span style="color:red" >{{item.Price-(orderdata.IsFullPayment==true?item.Provider.FullPaymentDiscount:0)-((item.Provider.IsNonStandard==true)?(data1.Account.BankName==null?item.Provider.NonstandardDiscount:0):0)-orderdata.ApplyDiscount}}/t</span></div>
                                                <div>件数：
                                                    <input ng-blur="sum()" type="number" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" min="1" ng-model="item.Count">
                                                    <!--{{item.Count}}-->
                                                </div>
                                                <div>
                                                    <span style="font-size: 0.8em; color: #999;" ng-if="item.Amount-(item.Count*item.Commodity.Weight)>=0">剩余库存：{{(item.Amount)-(item.Count*item.Commodity.Weight) | number:3}} t</span>
                                                    <span style="font-size: 0.8em; color: red" ng-if="((item.Amount)-(item.Count*item.Commodity.Weight) < 0)">暂无库存，无法购买！</span>
                                                </div>
                                                <div>总质量：{{item.Count}}*{{item.Commodity.Weight | number:3}}t={{(item.Count*item.Commodity.Weight).toFixed(3)}}t</div>
                                                <!--<div>总价：{{item.Count}}*{{item.Price}}*{{item.Commodity.Weight}}t={{item.Count*item.Price*item.Commodity.Weight.toFixed(2)}}</div>-->
                                                <!--<div>总价：{{item.Count}}*{{item.Price}}*{{item.Commodity.Weight}}t={{(item.Count*item.Price*item.Commodity.Weight) | number:2}}</div>-->
                                            </div>
                                            <div class="col-xs-3 col-md-3" style="text-align: center;">
                                                <button ng-disabled="item.Amount-(item.Count*item.Commodity.Weight)<0" type="button" class="btn btn-sm btn-default" ng-click="Countadd(item)" style="margin: 5px">
                                                    <i class="fa fa-plus text"></i>
                                                </button>
                                                <button type="button" class="btn btn-sm btn-default" ng-click="Countdeduct(item)" style="margin: 5px">
                                                    <i class="fa fa-minus text"></i>
                                                </button>
                                                <button type="button" class="btn btn-sm btn-danger" ng-click="deduct(item)" style="margin: 5px">
                                                    删除
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel-footer">
                                        <div>总价：{{item.Count==0?0:item.Count}}*{{item.Price}}*{{item.Commodity.Weight | number:3}}t={{((item.Count==0?0:item.Count)*item.Price*(item.Commodity.Weight | number:3)) | number:2}}</div>
                                    </div>
                                </div>
                            <div class="row text-left container-fluid">
                                <span>原始价格：{{originalTotal | number:2}}</span>
                            </div>
                            <div class="row text-left container-fluid" ng-if="orderdata.IsFullPayment && orderdata.Total > 0">
                                <span>先款优惠合计：{{originalxian | number:2}}</span>
                            </div>
                            <div class="row text-left container-fluid" ng-if="data1.Account.IsCash && orderdata.Total > 0">
                                <span>非标优惠合计：{{originalfei | number:2}}</span>
                            </div>
                            <div class="row text-left container-fluid" ng-if="orderdata.ApplyDiscount > 0 && orderdata.Total > 0">
                                <span>单价优惠合计：{{-originalApplyDiscount | number:2}}</span>
                            </div>
                            <div class="row text-left container-fluid" ng-if="orderdata.BargainingAmount > 0 && orderdata.Total > 0">
                                <span>总价优惠：{{orderdata.BargainingAmount | number:2}}</span>
                            </div>
                            <div class="row text-left container-fluid">
                                <span>总价：{{orderdata.Total | number:2}}</span>
                            </div>
                            <div class="row text-left container-fluid">
                                <span>预计运费价格：{{newWeight * orderdata.DeliveryPrice | number:2}}</span>
                            </div>
                           
                        </div>
                        <div class="row text-center" style="height: 40px;">
                            <a>
                                <div class="col-xs-6 col-md-6" style="display: inline-block;line-height: 100%;height: 100%;padding: 0px">
                                    <button type="button" style="width: 100%;height: 100%" class="btn btn-default" ng-click="abolish()">返回列表页</button>
                                </div>
                                <div class="col-xs-6 col-md-6" style="display: inline-block;line-height: 100%;height: 100%;padding: 0px">
                                    <button type="button" style="width: 100%;height: 100%" class="btn btn-success" ng-disabled="form.$invalid || orderdata.Total <=0" ng-click="ordersub()">提交计划单</button>
                                </div>
                            </a>
                        </div>
                    </div>
                </form>
            </div>
            <div ng-show="!isshow">
                <div class="container-fluid">
                    <div class="row" style="height: 40px;">
                    <a>
                        <div ng-click="xxx()" class="col-xs-6 col-md-6 text-left" style="display: inline-block;line-height: 100%;height: 100%">
                                    <span style="display: inline-block;line-height: 40px">
                                        <i class="fa fa-chevron-left text"></i>&nbsp;&nbsp;返回
                                    </span>
                        </div>
                    </a>
                    <div class="col-xs-6 col-md-6 text-center">
                        <select style="" class="btn btn-default" ng-model="findName" ng-change="genre(findName)">
                            <option value="盘螺">盘螺</option>
                            <option value="线材">线材</option>
                            <option value="钢坯">钢坯</option>
                            <option value="螺纹钢">螺纹钢</option>
                        </select>
                    </div>
                    </div>
                </div>

                <div class="panel panel-default" ng-repeat="item in ProviderCommodity" style="margin-bottom: 5px">
                    <div class="panel-heading">
                        <div>品牌：{{item.Commodity.Brand}}</div>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-xs-9 col-md-9">
                                <div>名称/材质/规格：{{item.Commodity.Name}}/{{item.Commodity.Standard}}/<span style="color: red">{{item.Commodity.Format}}</span></div>
                                <div>最低价格：{{item.Price | number:2}}￥<span ng-if="item.Price<=0" style="color: red;font-size: 12px">商品未定价，请联系运营改价</span></div>
                                <div>库存：{{item.Amount | number:3}}（t）</div>
                            </div>
                            <div class="col-xs-3 col-md-3" style="text-align: center; padding-top: 30px">
                                <button type="button" ng-show="!item.isadd" class="btn btn-sm btn-default" ng-click="add(item)">
                                    <i class="fa fa-plus text"></i>
                                    <span class="text">添加</span>
                                </button>
                                <button type="button" ng-show="item.isadd" class="btn btn-sm btn-default" ng-click="deduct(item)">
                                    <i class="fa fa-minus text"></i>
                                    <span class="text">取消</span>
                                </button>
                            </div>
                        </div>
                    </div>
                    <!--<div class="panel-footer">-->
                        <!--<div>总价：{{item.Count | number:2}}*{{item.Price | number:3}}*{{item.Commodity.Weight}}t={{(item.Count*item.Price*item.Commodity.Weight) | number:2}}</div>-->
                    <!--</div>-->
                </div>
                <!--<div class="input-group " style="margin-bottom: 20px">-->
                <!--<button type="button" class="btn btn-success" ng-click="xxx()">确认</button>-->
                <!--</div>-->
                <div class="row text-center" style="height: 40px;margin-top: 40px;">
                    <a>
                        <div class="col-xs-12 col-md-12" style="display: inline-block;line-height: 100%;height: 100%;">
                            <button type="button" style="width: 100%;height: 100%" class="btn btn-success" ng-click="xxx()">确认</button>
                        </div>
                    </a>
                </div>
            </div>

        </div>
    </div>
</div>
<script>
    angular.module('app')
        //创建计划单控制器
    .controller("orderAddC", function ($scope, $state, $http, $stateParams) {
        $scope.orderdata = {
            CommodityInfos: [],
            Total: 0,
            DeliveryPrice : 0,
            BargainingAmount : 0,
            OrderType:4
        };
        $scope.zuizhong = 0;
        $scope.zuihou = 0;
        $scope.hutou1=[]
        $scope.xiankuan = 0;
        $scope.feibiao = 0;
        $scope.Providerdata = {};
        $scope.searchTxt = "";
        $scope.type = JSON.parse($stateParams.type);
        // $('.kehu').eq(0).val().change(function(){
        //     alert(111)
        // })
        if($scope.type == 0){
            $scope.typeName = "钢厂";
            $scope.orderdata.OrderType = 0;
            $scope.myurl = "../api/Provider?type=0&page=1&rows=9999";
        }else if($scope.type == 4){
            $scope.typeName = "仓库";
            $scope.myurl = "../api/Provider?type=1&page=1&rows=9999";
            $scope.orderdata.OrderType = 4;
        }else if($scope.type == 2){
            $scope.typeName = "贸易商";
            $scope.myurl = "../api/Provider?type=2&page=1&rows=9999";
            $scope.orderdata.OrderType = 3;
        }
        $scope.minpriceFn = function(item){
            console.log(item.Price);
            console.log(item.minPrice);
            if(item.Price<item.minPrice){
                alert("不能小于最小售价");
                item.Price = item.minPrice;
            }
        };
        $scope.findName = '盘螺';
        $scope.data1 = {};
        $scope.isshow = true;
        $scope.isadd = true;
        $scope.selectedDistrict1 = "";
        $scope.client1 = "";
        $scope.cangku1 = "";
        $scope.Weight = 0;
        $scope.originalTotal = 0;
        $scope.originalxian = 0;
        $scope.originalfei = 0;
        $scope.originalApplyDiscount = 0;
        $scope.newDeliveryPriceTotal = 0;
        $scope.newWeight = 0;
        $scope.toggleText=false;
        $scope.hutou=[];
        $scope.data1 = {
                Account:{
                        IsCash:false
                }
        };
        $scope.FindAllBy = function () {
            $http({
                url: "../api/ClientManager/GetCustomer?name=" + $scope.searchTxt,
                method: "GET"
            })
           .then(function (res) {
               if (res.State <= 0) {
                   alert(res.Msg);
               } else {
                   $scope.client = res.data;
                   console.log($scope.client);
               }
           })
           .then(function (error) {
               if (error) {
                   console.log("error");
               }
           });
        }
        $scope.FindAllBy();
            // console.log( window.localStorage.getItem('districts'))
            // 获取地市
                    $scope.items = JSON.parse(window.localStorage.getItem('districts'));
        //获取供应商列表
        $http({
            url: $scope.myurl,
            method: "GET"
        })
            .then(function (res) {
                if (res.State <= 0) {
                    alert(res.Msg);
                } else {
                    console.log(res);
                    $scope.cangku = res.data.Data;
                }
            })
            .then(function (error) {
                if (error) {
                    console.log("error");
                }
            });
        //获取客户列表
       
        //提交编辑结果
        $scope.xxx = function () {
            if ($scope.orderdata.ProviderId) {
                $scope.sum();
                $scope.findName = '盘螺';
                $scope.genre('盘螺');//刷新商品列表，以防止价格不对
                $scope.isshow = !$scope.isshow;
            } else {
                alert("请选择供应商");
            }
                    $scope.zuihou=$scope.xiankuan;
        };
        $("#xiankuan").change(function () {
            $scope.sum();
        });
        $scope.none = function(){
        $scope.toggleText=false;
                
        };
        $scope.zipai = function(){
                $scope.orderdata.DeliveryPrice = 0;
        };
        //计算总价方法
        $scope.sum = function () {
            if ($scope.able==1) {
                for (var i = 0; i < $scope.orderdata.CommodityInfos.length; i++) {
                   if ($scope.orderdata.CommodityInfos[i].Count<=0) {
                    $scope.orderdata.CommodityInfos[i].Count=1;
                    alert('商品数量最小为1件');
                    break   
                   }
               }
            }
            if($scope.orderdata.IsDelivery){
                $scope.orderdata.DeliveryPrice = 0;
            }
            $scope.data2=$scope.data1.Account;
            $scope.orderdata.Total = 0;
            $scope.Weight = 0;
            $scope.newWeight = 0;
            $scope.originalApplyDiscount = 0;
            $scope.originalxian = 0;
            $scope.originalfei = 0;

            for (var i = 0; i < $scope.orderdata.CommodityInfos.length; i++) {
                $scope.Weight = $scope.orderdata.CommodityInfos[i].Count * $scope.orderdata.CommodityInfos[i].Commodity.Weight;
                $scope.orderdata.Total += $scope.Weight * $scope.orderdata.CommodityInfos[i].Price;
                $scope.originalTotal = $scope.orderdata.Total;

                $scope.newWeight += $scope.orderdata.CommodityInfos[i].Count*$scope.orderdata.CommodityInfos[i].Commodity.Weight;
            }
            //先款优惠
            if ($scope.orderdata.IsFullPayment && $scope.orderdata.Total > 0) {
                $scope.originalxian += ($scope.xiankuan * $scope.newWeight).toFixed(2);

            }
            //非标优惠
            if ($scope.data1.Account.IsCash && $scope.orderdata.Total > 0) {
                $scope.originalfei += ($scope.feibiao * $scope.newWeight).toFixed(2);
            }
            //申请单价优惠
            if ($scope.orderdata.ApplyDiscount > 0 && $scope.orderdata.Total > 0) {
                $scope.originalApplyDiscount -= ($scope.orderdata.ApplyDiscount * $scope.newWeight).toFixed(2);
            }
            
            //申请总价优惠
            $scope.orderdata.Total = $scope.orderdata.Total.toFixed(2) - $scope.originalxian - $scope.originalfei + $scope.originalApplyDiscount;
            $scope.able=1;
        };

                $scope.backf = function(){
                    if($scope.orderdata.IsFullPayment == true){
                        $scope.zuihou=$scope.xiankuan;
                    }else{
                        $scope.zuihou=0;
                    }
                }
        $scope.genre = function (name) {
            if (name != "" && $scope.depotId != "") {
//                if ($scope.type == 0 || $scope.type == 4) {
//                    $scope.model1 = $scope.orderdata.ProviderId;
//                }else if($scope.type == 2){
//                    $scope.model1 = "";
//                }
                $scope.model1 = $scope.orderdata.ProviderId;
                //获取仓库商品列表
                $http({
                    url: "../api/Provider/DepotCommodity?DepotId=" + $scope.model1 + "&name=" + name + "&format=&page=1&rows=9999",
                    method: "GET"
                })
                    .then(function (res) {
                        if (res.State <= 0) {
                            alert(res.Msg);
                        } else {
                            $scope.ProviderCommodity = res.data;
                            console.log(res);
                        }
                    })
                    .then(function (error) {
                        if (error) {
                            console.log("error");
                        }
                    });
            }
        };
        //添加到购物车
        $scope.add = function (item) {
            for (var i = 0; i < $scope.orderdata.CommodityInfos.length; i++) {
                if ($scope.orderdata.CommodityInfos[i].CommodityId == item.CommodityId) {
                    alert("商品已存在，不能重复添加");
                    return;
                }
            }
            if(item.Price <= 0){
                alert("商品未定价，请联系运营");
                return;
            }
            item.minPrice = angular.copy(item.Price);
            item.isadd = true;
            item.Count = 1;
            $scope.sum();
            $scope.orderdata.CommodityInfos.push(item);
        };
        //仓库改变清空购物车
       $scope.change1 = function () { 
            
            if ($scope.client1.ShortName==undefined) {
                alert('请先选择客户！')
                $scope.Providerdata='';
            }else{
                $scope.orderdata.ProviderId = $scope.Providerdata.Id;
                $scope.orderdata.CommodityInfos = [];
                $scope.xiankuan = $scope.Providerdata.FullPaymentDiscount;
                $scope.feibiao = $scope.Providerdata.NonstandardDiscount;
                $scope.client1=JSON.parse(localStorage.getItem('client1'))
                if ($scope.Providerdata.IsNonStandard != 1) {
                    debugger
                    //无非标优惠状态
                    for (var i = 0; i < $scope.client1.Accounts.length; i++) {
                        if (!$scope.client1.Accounts[i].IsCash ) {
                                //无非标优惠且户头公户
                                $scope.hutou=[];
                                $scope.hutou.push($scope.client1.Accounts[i]);
                                $scope.client1.Accounts=[];
                                $scope.client1.Accounts.push( $scope.hutou[i]);
                                if($scope.hutou[i].Id==$scope.data2.Id){
                                $scope.data1.Account= $scope.hutou[i]; }else{
                                    $scope.toggleText=true;
                                }
                        }else{
                            //无非标优惠且户头私户
                                $scope.data1.Account = [];
                                $scope.hutou1 = [];
                                for (var i = 0; i < $scope.client1.Accounts.length; i++) {
                                    if (!$scope.client1.Accounts[i].IsCash) {
                                        $scope.hutou1.push($scope.client1.Accounts[i])
                                    }
                                }
                                $scope.client1.Accounts=$scope.hutou1;
                                $scope.toggleText=true;
                            }
                    };
                }else if ($scope.Providerdata.IsNonStandard==1){
                //非标优惠状态
                    $scope.hutou=[];
                    console.log($scope.client1.Accounts)
                    for (var i = 0; i < $scope.client1.Accounts.length; i++) {
                                $scope.hutou.push($scope.client1.Accounts[i]);
                                if($scope.hutou[i].Id==$scope.data2.Id){
                                $scope.data1.Account= $scope.hutou[i];}
                    };
                } 
            }
        }
        //从购物车删除
        $scope.deduct = function (item) {
            $scope.able= 0;
            item.isadd = false;
            item.Count = 0;
            $scope.sum();
            for (var i = 0; i < $scope.orderdata.CommodityInfos.length; i++) {
                if ($scope.orderdata.CommodityInfos[i].CommodityId == item.CommodityId) {
                    $scope.orderdata.CommodityInfos.splice(i, 1);
                }
            }
        };
        //购物车增加数量
        $scope.Countadd = function (item) {
            item.Count += 1;
            $scope.sum();
        };
        //购物车减少数量
        $scope.Countdeduct = function (item) {
            if (item.Count > 0) {
                item.Count -= 1;
                $scope.sum();
            }
        };
        $scope.selectEmp = function (emp) {
            if ($scope.client1.ShortName!=undefined) {
                $scope.Providerdata='';
            }
            $scope.client1 = emp;  
            $scope.hutou=$scope.client1.Accounts;
            // for (var i = 0; i < $scope.hutou.length; i++) {
            //     if ($scope.hutou[i].BankName!=null) {
            //         $scope.data1.Account=$scope.hutou[i]
            //     }
            // }
            localStorage.setItem('client1', JSON.stringify($scope.client1));
            $scope.data1.Account = "";
            $('#dlg').modal("hide");
        };
        //提交计划单
        $scope.ordersub = function () {
            if($scope.orderdata.Total <= 0){
                alert("订单价格有误或未选择商品！请核对！")
            }else{
                $scope.orderdata.CustomerId = $scope.client1.Id;
                $scope.orderdata.AccountId = $scope.data1.Account.Id;
                if ($scope.orderdata.CommodityInfos.length < 1) {
                    alert("请添加商品")
                } else {
                    $http.post('../api/Order/Add', $scope.orderdata)
                            .success(function (res) {
                                if (res.State <= 0) {
                                    alert(res.Msg);
                                } else {
                                    alert("添加成功");
                                    $state.go('app.Order_MyorderList');
                                }
                            });
                }
            }
        };

        $scope.empty = function () {
            $scope.searchTxt = "";
        };
        //返回上一页
        $scope.abolish = function () {
            $state.go('app.Order_MyorderList');
        };
    })
</script>